/*
 * @(#)AbstractConfiguration.java   09/10/18
 * 
 * Copyright (C) 2009 Ecole des Mines d'Ales
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: yulinz88@gmail.com
 */



package fr.ema.arch3d.model.architecture.configuration;

import fr.ema.arch3d.model.architecture.specification.Specification;

import java.util.List;

//~--- classes ----------------------------------------------------------------

/**
 * Class description
 *
 *
 * @version 1.0, 09/09/16
 * @author Huaxi (Yulin) ZHANG
 */

/**
 * class description
 *
 * @version    version 15 oct. 2009
 * @author     Huaxi (Yulin) ZHANG
 */

/**
 * class description
 *
 * @version    version 18 oct. 2009
 * @author     Huaxi (Yulin) ZHANG
 */
public abstract class AbstractConfiguration implements Configuration {

//  /** a set of component classes construct this configuration */
//  private List<AbstractComponentClass> cmpClasses;

    /** The list contains a collection of Object[2] which contains {component class, component role name} */
    private List<Object[]> cmpImpl;

    /** The list contains a collection of Object[2] which contains {connector class, connection name} */
    private List<Object[]> connectorImpl;

//  /** a set of connector classes construct this configuration */
//  private List<AbstractConnectorClass> connectorClasses;

    /** the name of this configuration */
    private String name;

    /** the specification which is implemented by this configuration */
    private Specification specImpl;

    /**
     * Constructs the configuration with its name
     *
     * @param name  the name of this configuration
     */
    public AbstractConfiguration(String name) {
        super();
        this.name = name;
    }

    /**
     * Constructs  this configuration by its name, implemented specification and composed component 
     * classes and connector classes
     *
     * @param name  the name of this configuration
     * @param specImpl  the implemented specification of this configuration
     * @param cmpImpl  the component classes compose this configuration with their implement component
     * role names
     * @param connectorImpl  the connector classes compose this configuration with their implement connection names
     */
    public AbstractConfiguration(String name, Specification specImpl, List<Object[]> cmpImpl,
                                 List<Object[]> connectorImpl) {
        super();
        this.specImpl      = specImpl;
        this.cmpImpl       = cmpImpl;
        this.connectorImpl = connectorImpl;
        this.name          = name;
    }

    /**
     * Getter of the property <tt>name</tt>
     *
     * @return Returns the name.
     *
     */
    public String getName() {
        return this.name;
    }

    /**
     * Setter of the property <tt>name</tt>
     *
     * @param name
     *            the name of this configuration
     *
     */
    public void setName(String name) {
        this.name = name;
    }

//  /**
//   * Setter of the property <tt>cmpClasses</tt>
//   *
//   * @param cmpClasses
//   *            The cmpClasses to set.
//   *
//   */
//  @SuppressWarnings("unchecked")
//  public void setCmpClasses(List cmpClasses) {
//      this.cmpClasses = cmpClasses;
//  }
//  /**
//   * Setter of the property <tt>connectorClasses</tt>
//   *
//   * @param connectorClasses The connectorClasses to set.
//   *
//   */
//  @SuppressWarnings("unchecked")
//  public void setConnectorClasses(List connectorClasses) {
//      this.connectorClasses = connectorClasses;
//  }

    /**
     * Getter of the property <tt>specImpl</tt>
     *
     * @return  the specImpl
     */
    public Specification getSpecImpl() {
        return this.specImpl;
    }

    /**
     * Setter of the property <tt>specImpl</tt>
     *
     * @param specImpl  the specImpl to set
     */
    public void setSpecImpl(Specification specImpl) {
        this.specImpl = specImpl;
    }

    /**
     * Getter of the property <tt>cmpImpl</tt>
     *
     * @return  the cmpImpl
     */
    public List<Object[]> getCmpImpl() {
        return this.cmpImpl;
    }

    /**
     * Getter of the property <tt>connectorImpl</tt>
     *
     * @return  the connectorImpl
     */
    public List<Object[]> getConnectorImpl() {
        return this.connectorImpl;
    }

    /**
     * Inserts a <code>AbstractComponentClass</code>
     *
     * @param cmpClass  the <code>AbstractComponentClass</code> to add.
     * @param cmpRoleName  the component role name of which the component class implements
     */
    public void insertCmpClass(AbstractComponentClass cmpClass, String cmpRoleName) {
        Object[] cmp = { cmpClass, cmpRoleName };

        this.cmpImpl.add(cmp);
    }

    /**
     * Inserts a <code>AbstractConnectorClass</code>.
     *
     * @param connectorClass  the <code>AbstractConnectorClass</code> to insert
     * @param connectionName  the name of implemented connection of this inserted connector class
     */
    public void insertConnectorClass(AbstractConnectorClass connectorClass, String connectionName) {
        Object[] connector = { connectorClass, connectionName };

        this.connectorImpl.add(connector);
    }

    /**
     * Removes a <code>AbstractComponentClass</code>
     *
     * @param cmpClass  the <code>AbstractComponentClass</code> to remove.
     * @param cmpRoleName  the component role name of which the component class implements
     */
    public void removeCmpClass(AbstractComponentClass cmpClass, String cmpRoleName) {
        Object[] cmp     = { cmpClass, cmpRoleName };
        Boolean  success = this.cmpImpl.remove(cmp);

        if (success) {
            System.out.println("removing is done.");
        } else {
            System.err.println("No component class is found.");
        }
    }

    /**
     * Removes a <code>AbstractConnectorClass</code>
     *
     * @param connectorClass  the <code>AbstractConnectorClass</code> to remove.
     * @param connectionName  the name of implemented connection of this removed connector class
     */
    public void removeConnectorClass(AbstractConnectorClass connectorClass, String connectionName) {
        Object[] connector = { connectorClass, connectionName };
        Boolean  success   = this.connectorImpl.remove(connector);

        if (success) {
            System.out.println("removing is done.");
        } else {
            System.err.println("No component class is found.");
        }
    }
}
